package com.prs.crm.action.person;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.person.PostSet;
import com.prs.crm.service.person.PostSetService;

public class PostSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private PostSet postSet;
	private PostSetService postSetService;
	private List<PostSet> post;
	private PaginationSupport pagination;
	private Integer[] ids;
	public PostSet getPostSet() {
		return postSet;
	}
	public void setPostSet(PostSet postSet) {
		this.postSet = postSet;
	}
	public PostSetService getPostSetService() {
		return postSetService;
	}
	public void setPostSetService(PostSetService postSetService) {
		this.postSetService = postSetService;
	}
	public List<PostSet> getPost() {
		return post;
	}
	public void setPost(List<PostSet> post) {
		this.post = post;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	
	@Action("listPostSet")
	public String listPostSet(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(PostSet.class);
		pagination =this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getPostSetService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editPostSet")
	public String editPostSet(){
		this.post=this.getPostSetService().getAllPostSet();
		return SUCCESS;
	}
	@Action("editPostSets")
	public String editPostSets(){
		this.post=this.getPostSetService().getAllPostSet();
		return SUCCESS;
	}
	
	@Action(value="savePostSet",results={
			@Result(name="success",type="redirect",location="listPostSet"),
			@Result(name="error",type="chain",location="editPostSet")
	})
	public String savePostSet(){
		this.getPostSetService().save(postSet);
		return SUCCESS;
	}
	
	@Action(value="removePostSet",results={
			@Result(name="success",type="redirect",location="listPostSet"),
			@Result(name="error",type="chain",location="listPostSet")
	})
	public String removePostSet(){
		if(ids==null){
			this.addActionError("请选中一行进行操作！");
			return ERROR;
		}
		this.getPostSetService().batchRemove(ids);
		return SUCCESS;
	}
}
